package com.zyht.common.freemwork;

import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import com.zyht.common.bean.PropertiesUtilBean.PropertiesUtils;

/**
 * <b>描述：</b>	如果需要向视图中添加指定的值，使用此类<br/>
 * <b>作者：</b>zrb <br/>
 * <b>修改日期：</b>2016年5月17日 - 下午4:19:41<br/>
 *
 */
public class DataFreeMarkerViewResolver extends FreeMarkerViewResolver {
	
	private Map<String, Object> staticDatas = new ConcurrentHashMap<String, Object>(); 
	
	public DataFreeMarkerViewResolver(){
		super();
		staticDatas.putAll(PropertiesUtils.getAllProperties());
	}

	public void setStaticDatas(Map<String, Object> staticDatas){
		if(null!=staticDatas){
			this.staticDatas.putAll(staticDatas);
			getAttributesMap().putAll(staticDatas);
		}
	}

	public void setStaticMappings(Properties staticMappings){
		if(null!=staticMappings){
			for (Enumeration<?> names = staticMappings.propertyNames(); names.hasMoreElements();) {
				String dataMapping = (String) names.nextElement();
				staticDatas.put(dataMapping, staticMappings.getProperty(dataMapping));
			}
			getAttributesMap().putAll(staticDatas);
		}
	}
}
